package com.sanyang.pda.ui.Issuedwork;

import android.os.Bundle;
import android.provider.Settings;
import android.text.TextUtils;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.sanyang.pda.bean.AgvBean;
import com.sanyang.pda.bean.BindBgvinfoBean;
import com.sanyang.pda.bean.SelectBean;
import com.sanyang.pda.contract.LssuedSetContract;
import com.sanyang.pda.dialog.ConfrimDialog;
import com.sanyang.pda.presenter.LssuedSetPresenter;
import com.sanyang.pda.utils.PopUtisl;
import com.wangshen.base.app.AppActivityKey;
import com.wangshen.base.ui.mvp.base.ui.BaseMvpActivity;
import com.wangshen.projectbase.R;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

@Route(path = AppActivityKey.LSSUEDSETACTIVITY)
public class LssuedSetActivity extends BaseMvpActivity<LssuedSetPresenter> implements LssuedSetContract.View {
    @BindView(R.id.iv_back)
    ImageView ivBack;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.title)
    FrameLayout title;
    @BindView(R.id.tv_empty_pallet)
    TextView tvEmptyPallet;
    @BindView(R.id.tv_complete)
    TextView tvComplete;
    @BindView(R.id.tv_lssue)
    TextView tvLssue;
    @BindView(R.id.tv_bind)
    TextView tvBind;

    @Override
    public LssuedSetPresenter getPresenter() {
        return new LssuedSetPresenter();
    }

    @Override
    public int getView() {
        return R.layout.activity_lssued_set;
    }

    @Override
    public void initView() {
        presenter.getPadBindBgvinfoByPdaSn(Settings.Secure.getString(this.getContentResolver(), Settings.Secure.ANDROID_ID));
    }

    @Override
    public void initLinsenterner() {

    }

    @Override
    public void getData() {

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }

    @OnClick({R.id.iv_back, R.id.tv_empty_pallet, R.id.tv_complete, R.id.tv_lssue})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.iv_back:
                finishActivity();
                break;
            case R.id.tv_empty_pallet:
                presenter.getDeviceBaseInfoByType();
                break;
            case R.id.tv_complete:
                if (TextUtils.isEmpty(tvBind.getText())){
                    showMessage("请先绑定！");
                    return;
                }
                ConfrimDialog confrimDialog=new ConfrimDialog(mContext, new ConfrimDialog.Onclick() {
                    @Override
                    public void onConfirm() {
                        presenter.PDAlnbindAGv(Settings.Secure.getString(mContext.getContentResolver(), Settings.Secure.ANDROID_ID));
                    }
                });
                confrimDialog.show("确定要解绑吗");
                break;
            case R.id.tv_lssue:
                if (TextUtils.isEmpty(key)) {
                    showMessage("请先选择AGV");
                    return;
                }
                ConfrimDialog confrimDialog1=new ConfrimDialog(mContext, new ConfrimDialog.Onclick() {
                    @Override
                    public void onConfirm() {
                        presenter.getPDABindAGV(Settings.Secure.getString(mContext.getContentResolver(), Settings.Secure.ANDROID_ID), key);
                    }
                });
                confrimDialog1.show("确定要绑定吗");

                break;
        }
    }

    private String key;

    @Override
    public void setList(List<AgvBean> list) {
        List<SelectBean> selectBeans = new ArrayList<>();
        for (AgvBean storageBean : list) {
            selectBeans.add(new SelectBean(storageBean.getName(), String.valueOf(storageBean.getKey())));
        }
        PopUtisl.showSelectPop(LssuedSetActivity.this, selectBeans, tvEmptyPallet, new PopUtisl.SelectClick() {
            @Override
            public void onClick(SelectBean bean) {
                key = bean.getId();
                tvEmptyPallet.setText(bean.getName());
            }
        }, "请选择");
    }

    @Override
    public void setBindBean(BindBgvinfoBean bean) {
        tvBind.setText(bean.getAgvName());
    }

    @Override
    public void nobBind() {
        tvBind.setText("");
    }
}
